package com.woniuxy.driver.controller;



import com.woniuxy.commons.entity.Driver;
import com.woniuxy.commons.entity.vo.ResultVo;
import com.woniuxy.commons.util.NumberUtil;
import com.woniuxy.driver.service.DriverService;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @author rmw
 * @date 2020/12/4 17:57
 */
@RestController
@RequestMapping("/driver")
public class DriverController {
    @Autowired
    private DriverService driverService;

    @ResponseBody
    @RequestMapping("/register")
    public ResultVo<Object> register(Driver driver){
       //MD5加密(默认注册密码为123456)
        String pwd = driver.getPassword();
        String password = new SimpleHash("MD5",pwd,"tms",12).toString();
        //设置信息,模拟注册接口.后面会修改获取信息的方式
        driver.setDid(4).setNumber(NumberUtil.driverNo())
                .setPassword(password)
                .setName(driver.getName()).setAge(30).setSex(1)
                .setCard("23999000").setPhone("13938900043")
                .setTime(new Date()).setLicense("驾照")
                .setTid(2).setDbid(3).setBalance(new BigDecimal(30000));

       return driverService.register(driver);
    }

    @ResponseBody
    @RequestMapping("/login")
    public ResultVo<Object> login(){



        return null;
    }
}
